@extends('admin.pub.pub')
@section('title','权限管理')
@section('bread1','权限管理')
@section('bread2','权限列表')
@section('content')
    <div class="container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
			<span class="l">
				<a class="btn btn-primary radius" data-title="添加权限" data-href="{{ route('admin.permission.create') }}"
                   onclick="Hui_admin_tab(this)" href="javascript:;">
					<i class="Hui-iconfont">&#xe600;</i> 添加权限
				</a>
			</span>
        </div>
        <table class="table table-bordered table-hover">
            <thead>
            <tr>
                <th>ID</th>
                {{--<th>父级权限名称</th>--}}
                <th>权限名称</th>
                <th>路由别名</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $item)
                <tr>
                    <td>{{ $item['id'] }}</td>
                    {{--            <td>{{ $item['pid'] }}</td>--}}
                    <td>{{ $item['pid']==0?'':' ┗ ' }}{{ $item['name'] }}</td>
                    <td>{{ $item['route'] }}</td>
                    <td>
                        <button href="javascript:;"
                                onclick="edit_page('[{{ $item['name'] }}] 权限修改','{{ route('admin.permission.edit',['role'=>$item['id']]) }}')"
                                class="btn btn-primary">修改
                        </button>
                        <button href="javascript:;"
                                onclick="del('{{ route('admin.permission.destroy',['role'=>$item['id']]) }}')"
                                class="btn btn-danger">删除
                        </button>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
@endsection
@section('js')
    <script>
        // 编辑
        function edit_page(title, url) {
            layer.open({
                type: 2,
                title: title,
                content: url,
                area: ['500px', '450px']
            });
        }

        // 删除
        function del(url) {
            var _token = '{{ csrf_token() }}';
            $.ajax({
                url,
                type: 'delete',
                data: {_token},
                dataType: 'json',
                success(res) {
                    if (res.status == 0) {
                        layer.msg('成功', {
                            time: 1000
                        }, function () {
                            location.replace(location.href);
                        })
                    } else {
                        layer.alert('失败')
                    }
                }
            })
        }
    </script>
@endsection